//
//  GenericLoanHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

@objc protocol GenericLoanHeadViewdelegate {
    @objc optional func selectLoanType(index:Int) //选择贷款类型
}

class GenericLoanHeadView: UIView {
    
    weak var delegate : GenericLoanHeadViewdelegate?
    
    let workButton = ButtonView() //职业身份
    let linesButton = ButtonView() //贷款额度
    let typeButton = ButtonView() //抵押类型
    let moreButton = ButtonView() //更多
    
    init() {
        super.init(frame: .zero)
        
        workButton.tag = 1
        workButton.text = workStatus
        workButton.addTarget(self, action: #selector(selectLoanType(sender:)), for: .touchUpInside)
        self.addSubview(workButton)
        
        linesButton.tag = 2
        linesButton.text = loanLimit
        linesButton.addTarget(self, action: #selector(selectLoanType(sender:)), for: .touchUpInside)
        self.addSubview(linesButton)
        
        typeButton.tag = 3
        typeButton.text = mortgageType
        typeButton.addTarget(self, action: #selector(selectLoanType(sender:)), for: .touchUpInside)
        self.addSubview(typeButton)
        
        moreButton.image = UIImage.init(named: "double_arrow_right")
        moreButton.text = more_title
        self.addSubview(moreButton)
        
        let lineView = UIView()
        lineView.backgroundColor = UIColor.lineColor()
        self.addSubview(lineView)
        
        workButton.snp.makeConstraints { (make) in
            make.top.left.height.equalToSuperview()
            make.width.equalTo(ScreenW/4+RATIO(maxNum: 10))
        }
        
        linesButton.snp.makeConstraints { (make) in
            make.top.width.height.equalTo(workButton)
            make.left.equalTo(workButton.snp.right)
        }
        
        typeButton.snp.makeConstraints { (make) in
            make.top.width.height.equalTo(linesButton)
            make.left.equalTo(linesButton.snp.right)
        }
        
        moreButton.snp.makeConstraints { (make) in
            make.top.height.equalTo(typeButton)
            make.left.equalTo(typeButton.snp.right)
            make.right.equalToSuperview()
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
        
        
    }
    
    //MARK: 选择贷款类型
    @objc fileprivate func selectLoanType(sender:UIButton) {
        
        self.delegate?.selectLoanType!(index: sender.tag)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

}
